<template>
  <view class="charts-box">
    <qiun-data-charts
      type="line"
      :opts="opts"
      :chartData="chartData"
	  :ontouch="true"
    />
  </view>
</template>

<script>
export default {
  props:{
	 sale:{
		 type:Object,
		 default:{}
	 },
	wait:{
		type:Array,
		default:[]
	},
	settle:{
		type:Array,
		default:[]
	},
	total:{
		type:Array,
		default:[]
	},
	 time:{
		 type:Array,
		 default:[]
	 },
	  waitN:{
		  type:String,
		  default:''
	  },
	  settleN:{
		  type:String,
		  default:''
	  },
	  totalN:{
		  type:String,
		  default:''
	  },
	  isMule:{
		  type:Boolean,
		  default:false
	  }
  },
  data() {
    return {
      chartData: {},
      //您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
      opts: {
        color:['#ff4545','#6923ff','#e5e5e5'],
        padding: [10,10,10,0],
        dataLabel: false,
        dataPointShape: false,
        enableScroll:true,
        legend: {},
        xAxis: {
          disableGrid: true,
		 scrollShow: true,
		 itemCount: 7
        },
        yAxis: {
          gridType: "dash",
          dashLength: 1,
          data: []
        },
        extra: {
          line: {
            type: "curve",
            width: 2,
            activeType: "hollow",
            linearType: "custom",
            onShadow: false,
            animation: "horizontal"
          }
        }
      }
    };
  },
  onReady() {
    this.getServerData();
  },

  methods: {
	getdetData(name,actual,sale){
		if(this.isMule){
			this.chartData.series[0].name = name.waitN
			this.chartData.series[1].name = name.settleN
			this.chartData.series[2].name = name.totalN
			this.chartData.series[0].data= actual.wait
			this.chartData.series[1].data= actual.settle
			this.chartData.series[2].data= actual.total
		}else{
			this.chartData.series[0].name= name
			this.chartData.series[0].data= actual
			this.opts.yAxis.data.splice(0,this.opts.yAxis.data.length).push(sale)
		}
		 console.log(this.chartData,name,actual);
	},
    getServerData() {
      //模拟从服务器获取数据时的延时
      setTimeout(() => {
		  this.sale.max = Math.round(Number(this.sale.max))
		   this.sale.min = Math.round(Number(this.sale.min))
		  this.opts.yAxis.data.push(this.sale)
        //模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
        let res = {
            categories:this.time,
            series: [
              {
                name: this.waitN,
                linearColor: [
                  [
                    0,
                    "#ff4545"
                  ],
                  [
                    0.33,
                    "#ff4545"
                  ],
                  [
                    0.66,
                    "#ff4545"
                  ],
                  [
                    1,
                    "#ff4545"
                  ]
                ],
                setShadow: [
                  3,
                  8,
                  10,
                  "#ff4545"
                ],
                data: this.wait
              }
            ]
          };
		  if(this.isMule){
			  res.series.push(
			  	{
					name: this.settleN,
					linearColor: [
					  [
						0,
						"#6923ff"
					  ],
					  [
						0.25,
						"#6923ff"
					  ],
					  [
						0.5,
						"#6923ff"
					  ],
					  [
						0.75,
						"#6923ff"
					  ],
					  [
						1,
						"#6923ff"
					  ]
					],
					data: this.settle
				},
				{
					name: this.totalN,
					linearColor: [
					  [
						0,
						"#e5e5e5"
					  ],
					  [
						0.25,
						"#e5e5e5"
					  ],
					  [
						0.5,
						"#e5e5e5"
					  ],
					  [
						0.75,
						"#e5e5e5"
					  ],
					  [
						1,
						"#e5e5e5"
					  ]
					],
					data: this.total
				}	  
			)
		  }
		 
        this.chartData = JSON.parse(JSON.stringify(res));
		 console.log('11',this.chartData);
      }, 500);
    },
  }
};
</script>

<style scoped>
  /* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
  .charts-box {
    width: 100%;
    height: 300px;
  }
</style>